package edu.spec.pms.controller;

import edu.spec.pms.model.dto.MvcReturn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/admin/system")
public class SystemController {

	@ResponseBody
	@RequestMapping("/restartTomcat")
	public Object restartTomcat(){
		try {
			// 将脚本放于磁盘根目录没问题
			String cmd = "cmd /c start C:\\restarttomcat.bat";
			Process ps = Runtime.getRuntime().exec(cmd);
			//开发环境可以重启，运行环境stop后没有start
//			Process ps = Runtime.getRuntime().exec("C:\\Program Files\\Apache Software Foundation\\Tomcat 8.0\\bin\\restarttomcat.bat");
		} catch (Exception e) {
			e.printStackTrace();
			return new MvcReturn(false, null, "重启Tomcat失败");
		}
		return new MvcReturn(true);
	}

//	@ResponseBody
//	@RequestMapping("stopTomcat")
//	public Object stopTomcat(){
//		try {
//			String tomcatPath = PropertyHolder.getProperty("tomcat.stop");
//			Runtime   run   =   Runtime.getRuntime();
//			Process   pro   =   run.exec(tomcatPath);
//		} catch (IOException e) {
//			e.printStackTrace();
//			return new MvcReturn(false, null, "关闭Tomcat失败");
//		}
//		return new MvcReturn(true);
//	}
}
